/**
* PrimeNumbersSearcher.java 1.0 Jan 13, 2014
*
* Program should find prime numbers which are smaller or equal to the inputted 
* from keyboard integer number. Prime numbers - integral numbers that are not
* evenly divisible by any other numbers except for themselves and 1. 
* For example, for input number 6, the output of the program should be: [2, 3, 5].
*/

import java.util.*;

public class PrimeNumbersSearcher{
	
	public static void main(String[] args) throws java.io.IOException{
		System.out.println("Enter the integer number: ");
		Scanner in = new Scanner(System.in);
		while (!in.hasNextInt()){
			System.out.println("Incorrect value entered. Try again.");
			in = new Scanner(System.in);
		}
		int input = in.nextInt();
		int[] result = new int[input];
		int primeCounter = 0;
		for (int i = 1; i < input + 1; i++){
			boolean isPrime = true;
			for (int j = 2; j < i; j++){
				if (i%j == 0) isPrime = false;
				break;
			}
			if (isPrime == true) result[primeCounter++] = i;
		}
		result = Arrays.copyOf(result, primeCounter);
		System.out.println("The prime numbers are: " + Arrays.toString(result));
	}
}